#include <iostream>
#include <opencv2/opencv.hpp>
#include <filesystem>
using namespace cv;
using namespace std;
namespace fs = std::filesystem;

int main()
{
    fs::path currentPath = fs::current_path();
    cout << "current working direstory:" << currentPath << endl;

    // 构建图片路径
    fs::path imagePath = currentPath / ".." / "resource" / "x1.png";
    cout << "Image path: " << imagePath << endl;

    // 检查文件是否存在
    if (fs::exists(imagePath))
    {
        cout << "File exists: " << imagePath << endl;
    }
    else
    {
        cout << "File does not exist: " << imagePath << endl;
    }
    // 读取图片
    cv::Mat img = cv::imread(imagePath.string());
    if (img.empty())
    {
        cout << "Could not open or find the image: " << imagePath << endl;
        return -1;
    }

    // 检查OpenCV是否正确初始化
    if (!cv::haveImageReader(imagePath.string())) {
        cout << "OpenCV cannot read the image: " << imagePath << endl;
        return -1;
    }

    cv::imshow("image", img);
    cv::waitKey(0);
    return 0;
}